# 循环
a1 = 0
a2 = 0
while a1 < 10:
    print(a1, a1 + 1, end = "")# 0 11 22 33 44 55 66 77 88 99 10
    a1 += 1

print()

while a2 < 10:
    print(a2, a2 + 1, sep = "", end = "")# 011223344556677889910
    a2 += 1

print()

# for
for i in range(10):
    print(i, end = " ")# 0 1 2 3 4 5 6 7 8 9

print()

for i in range(3, 4):
    print('!')# !

for i in range(0, 5, 2):
    print(i, end = "")# 024

print()

# 模拟实现do_while
i = 0
while True:
    i += 1
    print('!', end = "")# !!!!!!
    if i > 5:
        break

print()

# python的循环支持搭配else，功能是当循环正常结束时，触发else，当循环因break等语句结束时，不触发else
my_set = {"Hello", 1, 5 ,2, 4}
for i in my_set:
    if i == 6:
        print("my_set has 6")
        break
else:
    print("my_set has not 6")# my_set has not 6

for i in range(2):
    print(i, end = "")# 01
else:
    print(1)# 1

#函数
def add(a, b):
    return a + b

# 常规传参方式
result = add(1,2)
print(result)

# 推荐传参方式
result2 = add(a = 1, b = 2)
print(result2)

# 注解示例
def func(n1, n2, n3)-> bool:
    if n1 > n2:
        return n1 + n2
    else:
        return n2 + n3
# def func():
#     print("hello")
print(func(n1 = 1, n2 = 2,n3 = 3))# 由于n1 < n2，所以返回n2 + n3 = 5


# 类和对象
class MyClass:
    def __init__(self, a, b):
        self.a = a
        self.b = b
    def print_myclass(self)->int:
        self.c = 996
        print(self.a, self.b, self.c, end = " ")
        return self.c

myclass = MyClass(a = 1, b = 2)
num = myclass.print_myclass()# 1 2 996

print()


# __slots__
class MySlotsClass:
    __slots__ = ("a", "b")
    def __init__(self, a, b):
        self.a = a
        self.b = b
        # self.c = 1
    def print_myslotsclass(self):
        print(self.a, self.b, end = " ")

myslots = MySlotsClass(a = 1, b = 2)
myslots.print_myslotsclass()# 1 2

print()


# # input
# nums = input("请输入一个整数：")
# print(nums)
#
#
# # input + 强转
# floatNum = float(input("请输入一个小数："))
# print(floatNum + 100)
#
#
# # input().split()模拟cin >> a >> b
# my_list = input("请输入两个整数：").split()
# int1 = int(my_list[0])
# int2 = int(my_list[1])
# print(int1 + int2)

# 使用map()函数 + 解包实现split + 强转
a1, a2 = map(int, input("请输入两个整数：").split())# 这里需要注意，传递函数时，直接传递函数名就可以了（类似C/C++，可以理解成函数名==函数指针），
                                  # 而传递函数名()就是调用该函数了，对于int()强转函数，其默认返回值是0
print(a1 + a2)

# 解包与可迭代对象
a3, a4 = [12, 564]
print(a3 + a4)








